
	<div id="action" class="easyui-dialog" closed="true" style="display:none;">
		<form class="easyui-form">
			<table>

				<tr>
					<td>手机号：</td>
					<td>
						<input name='phone' id="phone" type="text" placeholder="输入手机号">
					</td>
				</tr>

				<tr>
					<td>密码：</td>
					<td>
						<input name='password' id="password" type="text" placeholder="输入密码">
					</td>
				</tr>

				<tr>
					<td>昵称：</td>
					<td>
						<input name='nickname' id="nickname" type="text" placeholder="输入昵称">
					</td>
				</tr>

				<tr>
					<td>姓名：</td>
					<td>
						<input name='fullName' id="fullName" type="text" placeholder="输入姓名">
					</td>
				</tr>

				<tr>
					<td>身份证：</td>
					<td>
						<input name='idCard' id="idCard" type="text" placeholder="输入身份证">
					</td>
				</tr>

				<tr>
					<td>头像：</td>
					<td>
						<input name='pic' id='pic' type="file" onchange="product.upPic(this)">
					</td>
				</tr>

				<tr>
					<td>头像显示：</td>
					<td>
						<div id="picChild"></div>
					</td>
				</tr>

				<tr>
					<td>性别：</td>
					<td>
						<select name="gender" id="gender">
							<option value="1">男</option>
							<option value="2">女</option>
						</select>
					</td>
				</tr>

				<tr>
					<td>邮箱：</td>
					<td>
						<input name='eMail' id="eMail" type="text" placeholder="输入邮箱">
					</td>
				</tr>


				<tr>
					<td>地址的联系人：</td>
					<td>
						<input name='addressContacts' id="addressContacts" type="text" placeholder="输入地址的联系人">
					</td>
				</tr>


				<tr>
					<td>地址的手机号码：</td>
					<td>
						<input name='mobilePhoneNumberOfAddress' id="mobilePhoneNumberOfAddress" type="text" placeholder="输入地址的手机号码">
					</td>
				</tr>

				<tr>
					<td>地址的地区：</td>
					<td>
						<input name='addressArea' id="addressArea" type="text" placeholder="输入地址的地区">
					</td>
				</tr>

				<tr>
					<td>地址的详细地址：</td>
					<td>
						<input name='addressDetailAddress' id="addressDetailAddress" type="text" placeholder="输入地址的详细地址">
					</td>
				</tr>

				<tr>
					<td>地址的邮政编码：</td>
					<td>
						<input name='postalCodeOfAddress' id="postalCodeOfAddress" type="text" placeholder="输入地址的邮政编码">
					</td>
				</tr>



				<input type="hidden" name="id" id='id'>

			</table>
		</form>

	</div>

	<script type="text/javascript">

		function submit(id){

			var method = "/daoUsers/usersAdd";
			if(id > 0){
				var method = "/daoUsers/usersSaveData";
			}

	        var phone = $("#phone").val();
	        var password = $("#password").val();
	        var nickname = $("#nickname").val();
	        var fullName = $("#fullName").val();
	        var idCard = $("#idCard").val();

			// 图片上次错误提示
			picUrl = $('#picChild img').attr('src');
			/*if(picUrl == undefined){
				$.messager.alert('提示信息', "请上传多图片");
				return;
			}*/
			// 图片上传数据组合
			var picImg = new Array();
			$('.picImg').each(function(i, n){
				var src = $(this).attr('src');
				var savename = $(this).attr('savename');
				picImg[i] = {
					"firstPictureId":i,
					"firstPictureFileName":savename,
					"firstPictureAddress":src,
				}
			});
			var headPortrait  = JSON.stringify(picImg);

	        var gender = $("#gender").val();
	        var eMail = $("#eMail").val();

	        var addressContacts = $("#addressContacts").val();
	        var mobilePhoneNumberOfAddress = $("#mobilePhoneNumberOfAddress").val();
	        var addressArea = $("#addressArea").val();
	        var addressDetailAddress = $("#addressDetailAddress").val();
	        var postalCodeOfAddress = $("#postalCodeOfAddress").val();

	        $.messager.progress({msg:'正在增加...',interval:3000,});
			$.ajax({
				type:"post",
				url:method,
				data:{
					phone:phone,
					password:password,
					nickname:nickname,
					fullName:fullName,
					idCard:idCard,
					headPortrait:headPortrait,
					gender:gender,
					eMail:eMail,
					addressContacts:addressContacts,
					mobilePhoneNumberOfAddress:mobilePhoneNumberOfAddress,
					addressArea:addressArea,
					addressDetailAddress:addressDetailAddress,
					postalCodeOfAddress:postalCodeOfAddress,
					id:id,
				},
				cache: false,
				dataType:'html',
				success:function(data){

					var data = eval('('+data+')');
					if( data.info == 'success' ){
						
						$.messager.progress('close');
						$('#action').dialog('close');
						$('#data').datagrid('reload');
					} else {
						
						$.messager.progress('close');
						$.messager.alert('提示信息', data.info);
					}
				}
			});

		}

		function doAdd(id, data){

			$("#action form").form('reset');

			var title = '新增';
			if(id > 0){
				var title = '修改';
				$("#phone").val(data.phone);
				$("#password").val(data.password);
				$("#nickname").val(data.nickname);
				$("#fullName").val(data.fullName);
				$("#idCard").val(data.idCard);

				// 多图
				var headPortrait = jQuery.parseJSON(data.headPortrait);
				for (var i = 0; i < headPortrait.length; i++) {
					var productAddress = headPortrait[i].firstPictureAddress;
					var productFileName = headPortrait[i].firstPictureFileName;
					$('#picChild').append("<div class='picShowWrap' style='width:100px;height:100px;position:relative;display:inline-block;float:left;'>"
											+"<img class='picImg' width='100' height='100' src='"+productAddress+"' savename='"+productFileName+"'/>"
											+"<button onclick='product.removePic(this)' style='position: absolute;right:0px;bottom:0px'>删除</button>"
											+"</div>");
				}

				$("#gender").val(data.gender);
				$("#eMail").val(data.eMail);
				$("#addressContacts").val(data.addressContacts);
				$("#mobilePhoneNumberOfAddress").val(data.mobilePhoneNumberOfAddress);
				$("#addressArea").val(data.addressArea);
				$("#addressDetailAddress").val(data.addressDetailAddress);
				$("#postalCodeOfAddress").val(data.postalCodeOfAddress);

				$("#id").val(data.id);

			}else{
				// authority.list();
			}

			$('#action').show();
			$('#action').dialog('open').dialog({
				title:title,    
				width:"100%",    
				height:"100%",
				closed:false,    
				cache:false,    
				modal:true,
				closable:true, 
				left:0,
				top:0,
				buttons:[{
					text:'确定',
					width:'56',
					handler:function(){

						submit(id);
					}
				},{
					text:'取消',
					width:'56',
					handler:function(){

						$('#action').dialog('close');
					}
				}],
			});

		}

	</script>
